<?php

namespace liketry\controllers;

use Yii;


class CustomController extends \yii\web\Controller
{
    public $bestry_uid;
    public $liketry_uid;
    public $login_url;
    //public $enableCsrfValidation = false;

      
    public function beforeAction($action)
    {
        
        $this->login_url = Yii::$app->params['pc_login_url'].urlencode(Yii::$app->request->getHostInfo().Yii::$app->request->url);
        
        /*$actionID = Yii::$app->controller->action->id;//当前方法

         //其他页面没有登陆回到登陆页面
         if (!$this->isLogin() && (!in_array($actionID, array('login','captcha')))) {
            $this->redirect(['site/login']);
         }
         //如果登陆过了，跳转到登陆页面自动跳转到首页
         if ($this->isLogin() && ($actionID =='login')) {
             $this->redirect(['site/index']);
         }*/
         $ip = Yii::$app->request->getUserIP();
        if($ip == '127.0.0.1' || $ip == '::1'){
            Yii::$app->session->set(Yii::$app->params['member_no'], 1);
            Yii::$app->session->set(Yii::$app->params['uid'], 1522091);
        }


        $this->liketry_uid = intval(Yii::$app->session->get(Yii::$app->params['member_no']));
        $this->bestry_uid = intval(Yii::$app->session->get(Yii::$app->params['uid']));
        //note:此处before 只能返回false true $this->bestry_id 赋值失效 建议放到配置项内  确认后 请删除 TODO


        return parent::beforeAction($action);
    }

    public function actions()
    {
        return parent::actions()+['error' => [
            'class' => 'yii\web\ErrorAction',
        ]];
    }

    /**
     * 判断用户是否登陆
     * @return boolean
     */
    protected function isLogin()
    {
        return boolval(Yii::$app->session->get(Yii::$app->params['uid']));
    }
}
